/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package editor;

import java.io.File;
import javax.swing.JFileChooser;

/**
 *
 * @author Roderick
 */
public class DlgNewProject extends javax.swing.JDialog {
    private boolean status;

    /**
     * Creates new form DlgNewProject2
     */
    public DlgNewProject(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        txtProjectName = new javax.swing.JTextField();
        txtProjectLocation = new javax.swing.JTextField();
        btnBrowseProject = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        txtProjectFolder = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        btnCancel = new javax.swing.JButton();
        btnFinish = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("editor/bundle/DialogsBundle_es_PE"); // NOI18N
        jLabel1.setText(bundle.getString("project_name")); // NOI18N

        jLabel2.setText(bundle.getString("project_location")); // NOI18N

        txtProjectName.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                txtProjectNamePropertyChange(evt);
            }
        });
        txtProjectName.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtProjectNameKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtProjectNameKeyReleased(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtProjectNameKeyTyped(evt);
            }
        });

        txtProjectLocation.setEditable(false);

        btnBrowseProject.setText(bundle.getString("browse")); // NOI18N
        btnBrowseProject.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBrowseProjectActionPerformed(evt);
            }
        });

        jLabel5.setText(bundle.getString("project_folder ")); // NOI18N

        txtProjectFolder.setEditable(false);

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel6.setText(bundle.getString("name_and_location")); // NOI18N

        btnCancel.setText(bundle.getString("cancel")); // NOI18N
        btnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelActionPerformed(evt);
            }
        });

        btnFinish.setText(bundle.getString("finish")); // NOI18N
        btnFinish.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnFinishActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel5))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtProjectName)
                    .addComponent(txtProjectLocation)
                    .addComponent(txtProjectFolder, javax.swing.GroupLayout.PREFERRED_SIZE, 465, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnBrowseProject)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(jLabel6)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnFinish)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnCancel)
                .addGap(10, 10, 10))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(8, 8, 8)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtProjectName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtProjectLocation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnBrowseProject))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txtProjectFolder, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnCancel)
                    .addComponent(btnFinish))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel6.getAccessibleContext().setAccessibleName(bundle.getString("name_and_location")); // NOI18N

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnBrowseProjectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBrowseProjectActionPerformed
        JFileChooser fileChooser = new JFileChooser();
        fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        int result = fileChooser.showSaveDialog(null);
        if (result == JFileChooser.CANCEL_OPTION) {
            return;
        }
        txtProjectLocation.setText(fileChooser.getSelectedFile().getAbsolutePath());
        txtProjectFolder.setText(txtProjectLocation.getText() + File.separator + txtProjectName.getText());
    }//GEN-LAST:event_btnBrowseProjectActionPerformed

    private void btnFinishActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFinishActionPerformed
        status = true;
        this.setVisible(false);
    }//GEN-LAST:event_btnFinishActionPerformed

    private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
        status = false;
        this.setVisible(false);
    }//GEN-LAST:event_btnCancelActionPerformed

    private void txtProjectNameKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtProjectNameKeyReleased
        if (!txtProjectLocation.getText().equals("")) {
            txtProjectFolder.setText(txtProjectLocation.getText() + File.separator + txtProjectName.getText());
        }
    }//GEN-LAST:event_txtProjectNameKeyReleased

    private void txtProjectNameKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtProjectNameKeyPressed
    }//GEN-LAST:event_txtProjectNameKeyPressed

    private void txtProjectNameKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtProjectNameKeyTyped
    }//GEN-LAST:event_txtProjectNameKeyTyped

    private void txtProjectNamePropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_txtProjectNamePropertyChange
    }//GEN-LAST:event_txtProjectNamePropertyChange

    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnBrowseProject;
    private javax.swing.JButton btnCancel;
    private javax.swing.JButton btnFinish;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JTextField txtProjectFolder;
    private javax.swing.JTextField txtProjectLocation;
    private javax.swing.JTextField txtProjectName;
    // End of variables declaration//GEN-END:variables

    public boolean isStatus() {
        return status;
    }

    public String getTxtPath() {
        return this.txtProjectFolder.getText();
    }
}
